package be.sc.classicnetwork.dao;

import java.util.List;

import be.sc.classicnetwork.model.AbstractEntity;

/**
 * Super interface for DAOs having common CRUD functionalities.
 */
public interface GenericDao<T extends AbstractEntity> {
	/**
	 * Finds the specified entity. The default fetching strategy defined by the
	 * attribute annotions will be used.
	 * 
	 * @param id
	 *            the entity id
	 * @return the entity or null if not found
	 */
	T findById(String id);

	/**
	 * Finds the specified entity. All the relationships (OneToMany) will be
	 * fetched.
	 * 
	 * @param id
	 *            the entity id
	 * @return the entity or null if not found
	 */
	T findByIdFull(String id);

	/**
	 * Gets all the entities.
	 * 
	 * @param first
	 *            the first result (from 0)
	 * @param max
	 *            the max number of record to retrieve (<= 0 for no limit)
	 * @return a List of 0 or more persitent entities
	 */
	List<T> findAll(int first, int max);

	/**
	 * Generates a unique entity id and saves (insert or update) the specified
	 * entity.
	 * 
	 * @param entity
	 *            the entity
	 * @return a reference to the saved entity
	 */
	T saveOrUpdate(T entity);

	/**
	 * Deletes the specified entity.
	 * 
	 * @param entity
	 *            the entity
	 */
	void delete(T entity);

	/**
	 * Deletes all the entities.
	 */
	void deleteAll();

	/**
	 * Counts all the entities.
	 * 
	 * @return the numbers of entities
	 */
	int countAll();

	/**
	 * Finds all the entities having the specified ids.
	 * 
	 * @param ids
	 */
	List<T> findByIdIn(String... ids);

}
